﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SJZD_NameManage : ATPages
{
    ZSql zsql = new ZSql();

    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hfxs.Value = Request.QueryString["moduid"].ToString();
            lblwz.Text = f.getModuleidAdd(hfxs.Value);

            //gdata();
            initData();
        }
    }
   
    //protected void lnkbtnFlag_Click(object sender, EventArgs e)
    //{
    //    string SpecificationsId = (sender as LinkButton).CommandArgument.ToString();
    //    Response.Redirect("AddSpecifications.aspx?SpecificationsId=" + SpecificationsId + "&moduid=" + hfxs.Value + "&action=flag");

    //}

    //protected void lnkbtnEdit_Click(object sender, EventArgs e)
    //{
    //    string SpecificationsId = (sender as LinkButton).CommandArgument.ToString();
    //    Response.Redirect("AddSpecifications.aspx?SpecificationsId=" + SpecificationsId + "&moduid=" + hfxs.Value + "&action=update");

    //}
    private void initData()
    {
        string sql = "select  WarehouseName,ComoditiesId,f.SpecificationsId,a.warehouseid,typeStock,ComodBarcode,ProcMoney,WholeMoney1,WholeMoney2,RestMoney,ChainMoney,Prices,RetailMoney,SuppliMoney,ActiveMoney,d.Brand,e.ComoditiesName,f.Specifications,j.Units,h.Supplier,ComodBarcode,TotalNum from CS_stock a join CS_Warehouse b on a.warehouseid=b.WarehouseId join ComoditiesType c on a.ComoditiesType=c.TypeId join Brand d on a.BrandId=d.BrandId join ComoditiesName e on a.ComoditiesName=e.ComoditiesNameId join Specifications f on a.ModelId=f.SpecificationsId join Units j on a.UnitId=j.UnitsId join CS_Supplier h on a.SuppliId=h.SupplierId";

        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }


    protected void btnSelec_Click(object sender, EventArgs e)
    {
        string sql = "select  WarehouseName,ComoditiesId,f.SpecificationsId,a.warehouseid,typeStock,ComodBarcode,ProcMoney,WholeMoney1,WholeMoney2,RestMoney,ChainMoney,Prices,RetailMoney,SuppliMoney,ActiveMoney,d.Brand,e.ComoditiesName,f.Specifications,j.Units,h.Supplier,ComodBarcode,TotalNum from CS_stock a join CS_Warehouse b on a.warehouseid=b.WarehouseId join ComoditiesType c on a.ComoditiesType=c.TypeId join Brand d on a.BrandId=d.BrandId join ComoditiesName e on a.ComoditiesName=e.ComoditiesNameId join Specifications f on a.ModelId=f.SpecificationsId join Units j on a.UnitId=j.UnitsId join CS_Supplier h on a.SuppliId=h.SupplierId";
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%"+Common.FormatParameter(txtseletype.Text)+"%'";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%' ";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%' ";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%' ";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text )+ "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%' ";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'";
                        }
                    }
                }
            }
        }
       
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' ";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%'  and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text )+ "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' ";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text != "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                        else
                        {
                            sql += " where c.ComoditiesType like'%" + Common.FormatParameter(txtseletype.Text) + "%' and f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                    }
                }
            }
        }
           if (txtseletype.Text == "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += "";
                        }
                        else
                        {
                            sql += " where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text == "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%' ";
                        }
                        else
                        {
                            sql += " where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text == "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%' ";
                        }
                        else
                        {
                            sql += " where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text == "")
        {
            if (txtseleband.Text == "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += "  where e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%' ";
                        }
                        else
                        {
                            sql += "  where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text == "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += "  where d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%' ";
                        }
                        else
                        {
                            sql += "  where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text == "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text == "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += "  where d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' ";
                        }
                        else
                        {
                            sql += "  where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' ";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text == "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text != "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += "  where d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                        else
                        {
                            sql += "  where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%' and ComodBarcode like'%" + Common.FormatParameter(txtbh.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                    }
                }
            }
        }
        if (txtseletype.Text == "")
        {
            if (txtseleband.Text != "")
            {
                if (txtselename.Text != "")
                {
                    if (txtbh.Text == "")
                    {
                        if (txtselecName.Text == "")
                        {
                            sql += " where d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text)+ "%'";
                        }
                        else
                        {
                            sql += " where f.Specifications like'%" + Common.FormatParameter(txtselecName.Text) + "%'  and d.Brand like'%" + Common.FormatParameter(txtseleband.Text) + "%'  and e.ComoditiesName like'%" + Common.FormatParameter(txtselename.Text) + "%'";
                        }
                    }
                }
            }
        }
        sql += " and TotalNum>0 order by stockId desc";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;

    }

  
  
    protected void GvDataSp_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        ZSql sel = new ZSql();
        sel.Open("select * from CS_Param");

        if (sel.m_table.Rows[0]["IsPrice"].ToString() == "0")
        {
            GvDataSp.Columns[5].Visible = false;
        }
        if (sel.m_table.Rows[0]["IsrestPrice"].ToString() == "0")
        {
            GvDataSp.Columns[4].Visible = false;
        }
        sel.Close();
    }
}
